import { hasPermission } from '@/utils/permission'

export default {
  install(Vue) {
    // 权限指令
    Vue.directive('permission', {
      inserted(el, binding) {
        const { value } = binding
        const hasAccess = hasPermission(value)
        
        if (!hasAccess) {
          el.parentNode && el.parentNode.removeChild(el)
        }
      }
    })

    // 角色指令
    Vue.directive('role', {
      inserted(el, binding) {
        const { value } = binding
        const hasAccess = hasPermission(value)
        
        if (!hasAccess) {
          el.parentNode && el.parentNode.removeChild(el)
        }
      }
    })
  }
} 